uniform sampler3D volume; 
uniform float cutoffValue;
//flat shading

void main()
{
	vec3 newCoords = vec3(gl_TexCoord[0].x, gl_TexCoord[0].y, gl_TexCoord[0].z);

	float newX = gl_TexCoord[0].x;// + 0.03;
	float newY = gl_TexCoord[0].y;// + 0.03;
	float newZ = gl_TexCoord[0].z;// + 0.03;
	if(newX > 1.0) newX = 1.0;
	if(newY > 1.0) newY = 1.0;
	if(newZ > 1.0) newZ = 1.0;
	
	vec3 newCoordsShifted = vec3(newX, newY, newZ);
	//vec4 c = texture3D(volume, vec3(gl_TexCoord[0]));
	//vec4 c = texture3D(volume, newCoords);
	vec4 c = texture3D(volume, newCoords);
	vec4 cShifted = texture3D(volume, newCoordsShifted);
	
	c.a = smoothstep(0.1, 0.8, c.a);
	cShifted.a = smoothstep(0.1, 0.8, cShifted.a);
    
//	if(c.a < 0.1)
    if(cShifted.a < cutoffValue)//0.1)
	{
		//gl_FragColor = gl_Color * c.a;
		gl_FragColor = vec4(1.0, 0.0, 0.0, 0.0);//totally transparent
	}
	//we're rendering flat everything that is more than a threshold
	//i.e. lower opacity is actually not drawn, but higher opacity
	//is now flat
	else
	{
		gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);// * cShifted.a;
		//gl_FragColor = vec4(0.0, 0.0, 0.5, 1.0);
	}
	
	//gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
